package com.sync;

public class DisSync1 implements Runnable {

    static int i = 0;
    static DisSync1 dis = new DisSync1();

    public static void main(String[] args)throws Exception {
        Thread t1 = new Thread(dis,"t1");
        Thread t2 = new Thread(dis,"t2");
        t1.start();
        t2.start();
        // 通过join保证两个线程都执行完成
        t1.join();
        t2.join();

        System.out.println(i);
    }

    @Override
    public synchronized void run() {
        System.out.println(Thread.currentThread()+"开始执行");
        for (int j = 0; j < 100000; j++) {
            i ++;
        }
        System.out.println(Thread.currentThread()+"执行完毕");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {

        }
    }
}
